import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class ChatClient {


    public static void main(String[] args) {
        new ChatClient();
    }

    public ChatClient() {
        try {
            Socket client = new Socket("107-70",9900);
            //向服务器段发送姓名,发送要有输出流OutPutStream
            OutputStream os = client.getOutputStream();
            //封装成高级的对象输出流
            ObjectOutputStream oos = new ObjectOutputStream(os);
            //控制台录入姓名并发送到服务器段
            System.out.println("请输入姓名:");
            Scanner scanner = new Scanner(System.in);
            String name = scanner.nextLine();
            oos.writeObject(name);
            //接收从服务器段发送的欢迎信息，用InputStraem
            InputStream is = client.getInputStream();
//封装成对象输入流
            ObjectInputStream ois = new ObjectInputStream(is);
            String msg = (String) ois.readObject();
            System.out.println(msg);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }


    }
}
